<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>解密函数 | siphan</title>
    <meta name="description" content="一个简单易用的 JavaScript 前端加密库">
    <meta name="generator" content="VuePress 1.3.0">
    
    
    <link rel="preload" href="/siphan/assets/css/0.styles.bab5f12a.css" as="style"><link rel="preload" href="/siphan/assets/js/app.a096c374.js" as="script"><link rel="preload" href="/siphan/assets/js/2.b96ecc85.js" as="script"><link rel="preload" href="/siphan/assets/js/7.0de11c07.js" as="script"><link rel="prefetch" href="/siphan/assets/js/10.e5803348.js"><link rel="prefetch" href="/siphan/assets/js/11.1506d706.js"><link rel="prefetch" href="/siphan/assets/js/12.9fea4da3.js"><link rel="prefetch" href="/siphan/assets/js/3.c42c2ebd.js"><link rel="prefetch" href="/siphan/assets/js/4.5f9aa696.js"><link rel="prefetch" href="/siphan/assets/js/5.537dfae2.js"><link rel="prefetch" href="/siphan/assets/js/6.c506cd42.js"><link rel="prefetch" href="/siphan/assets/js/8.83590e60.js"><link rel="prefetch" href="/siphan/assets/js/9.b0b386d5.js">
    <link rel="stylesheet" href="/siphan/assets/css/0.styles.bab5f12a.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/siphan/" class="home-link router-link-active"><img src="https://s2.ax1x.com/2020/02/26/3aERFe.png" alt="siphan" class="logo"> <span class="site-name can-hide">siphan</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/siphan/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/siphan/guide/" class="nav-link">
  入门
</a></div><div class="nav-item"><a href="/siphan/API/" class="nav-link router-link-active">
  API
</a></div><div class="nav-item"><a href="http://service.shawroger.com/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  示例
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://gitee.com/shawroger/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  仓库
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/siphan/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/siphan/guide/" class="nav-link">
  入门
</a></div><div class="nav-item"><a href="/siphan/API/" class="nav-link router-link-active">
  API
</a></div><div class="nav-item"><a href="http://service.shawroger.com/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  示例
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://gitee.com/shawroger/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  仓库
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>API</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/siphan/API/" class="sidebar-link">加密函数</a></li><li><a href="/siphan/API/decrypt.html" class="active sidebar-link">解密函数</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/siphan/API/decrypt.html#decrypt" class="sidebar-link">decrypt</a></li><li class="sidebar-sub-header"><a href="/siphan/API/decrypt.html#decryptutf8" class="sidebar-link">decryptUTF8</a></li></ul></li><li><a href="/siphan/API/config.html" class="sidebar-link">自定义对象</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="解密函数"><a href="#解密函数" class="header-anchor">#</a> 解密函数</h1> <h2 id="decrypt"><a href="#decrypt" class="header-anchor">#</a> decrypt</h2> <p><strong>decrypt</strong> 用来解密非 UTF8 字符的密钥</p> <blockquote><p><strong>decrypt</strong> 函数不会先对密钥进行检查，如有必要，请先使用 <a href="/siphan/API/#createkey">checkkey</a> 检查</p></blockquote> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">function</span> <span class="token function">decrypt</span><span class="token punctuation">(</span><span class="token parameter">str<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">,</span> solution<span class="token operator">:</span> <span class="token builtin">string</span></span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">;</span>
</code></pre></div><blockquote><p><strong>cipher</strong> 是生成的密文，
<strong>solution</strong> 是解密的密钥</p></blockquote> <ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> decrypt <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> result <span class="token operator">=</span> <span class="token function">decrypt</span><span class="token punctuation">(</span>cipher<span class="token punctuation">,</span> solution<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="decryptutf8"><a href="#decryptutf8" class="header-anchor">#</a> decryptUTF8</h2> <p><strong>decryptUTF8</strong> 用来解密 UTF8 字符的密钥</p> <blockquote><p>与 <strong>decrypt</strong> 函数相似， <strong>encryptUTF8As</strong> 函数也不会先对密钥进行检查</p></blockquote> <blockquote><p>由于 <strong>decryptUTF8</strong> 函数将先进行解码，<strong>decryptUTF8</strong> 支持对解码错误进行处理</p></blockquote> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">function</span> <span class="token function">decryptUTF8</span><span class="token punctuation">(</span>
	<span class="token parameter">cipher<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">,</span>
	solution<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">,</span>
	callback<span class="token operator">?</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">err<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token operator">...</span>args<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">[</span><span class="token punctuation">]</span></span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token builtin">any</span></span>
<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">string</span> <span class="token operator">|</span> <span class="token keyword">undefined</span>
</code></pre></div><blockquote><p><strong>cipher</strong> 是生成的密文，
<strong>solution</strong> 是解密的密钥</p></blockquote> <blockquote><p><strong>callback</strong> 在解码错误是会进行回调，接受一个错误信息，也可以不传参，这将直接返回 <strong>undefined</strong></p></blockquote> <ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> decryptUTF8 <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> result <span class="token operator">=</span> <span class="token function">decryptUTF8</span><span class="token punctuation">(</span>cipher<span class="token punctuation">,</span> solution<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">err</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/siphan/API/" class="prev router-link-active">
        加密函数
      </a></span> <span class="next"><a href="/siphan/API/config.html">
        自定义对象
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/siphan/assets/js/app.a096c374.js" defer></script><script src="/siphan/assets/js/2.b96ecc85.js" defer></script><script src="/siphan/assets/js/7.0de11c07.js" defer></script>
  </body>
</html>
